package com.android.readcard.utils.djlm.DJLMReader3.reader;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

/**
 * Created by Sabirjan on 2017/10/13.
 * DJLMReader.
 * 飞宏电子
 */

public class AppInfoTools {
    public static String GetSystemInfo(Context ctx) {
        String handSetInfo =
                "MobileType:" + android.os.Build.MODEL +
                        ",SDK:" + android.os.Build.VERSION.SDK +
                        ",SysVer:" + android.os.Build.VERSION.RELEASE +
                        ",SoftVer:" + getAppVersionName(ctx);
        return handSetInfo;
    }

    //获取当前版本号
    public static String getAppVersionName(Context context) {
        String versionName = "";
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            versionName = packageInfo.versionName;
            if (TextUtils.isEmpty(versionName)) {
                return "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return versionName;
    }

    public static String GetNetworkType(Context context) {
        String strNetworkType = "";
        try {
            ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = manager.getActiveNetworkInfo();
            if (networkInfo != null && networkInfo.isConnected()) {
                strNetworkType = networkInfo.getTypeName();
                if (strNetworkType.equalsIgnoreCase("MOBILE")) {
                    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                    switch (telephonyManager.getNetworkType()) {
                        case TelephonyManager.NETWORK_TYPE_1xRTT:
                            strNetworkType = "1xRTT"; // ~ 50-100 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_CDMA:
                            strNetworkType = "CDMA";// ~ 14-64 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_EDGE:
                            strNetworkType = "EDGE"; // ~ 50-100 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_EVDO_0:
                            strNetworkType = "EVDO_0"; // ~ 400-1000 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_EVDO_A:
                            strNetworkType = "EVDO_A"; // ~ 600-1400 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_GPRS:
                            strNetworkType = "GPRS";// ~ 100 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_HSDPA:
                            strNetworkType = "HSDPA";// ~ 2-14 Mbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_HSPA:
                            strNetworkType = "HSPA";// ~ 700-1700 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_HSUPA:
                            strNetworkType = "HSUPA";// ~ 1-23 Mbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_UMTS:
                            strNetworkType = "UMTS"; // ~ 400-7000 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_EHRPD:
                            strNetworkType = "EHRPD"; // ~ 1-2 Mbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_EVDO_B:
                            strNetworkType = "EVDO_B";// ~ 5 Mbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_HSPAP:
                            strNetworkType = "HSPAP";// ~ 10-20 Mbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_IDEN:
                            strNetworkType = "IDEN"; // ~25 kbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_LTE:
                            strNetworkType = "LTE";// ~ 10+ Mbps
                            break;
                        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                            strNetworkType = "UNKNOWN";
                            break;
                    }
                }
            } else
                strNetworkType = "";
        } catch (Exception ex) {
        }
        return strNetworkType;
    }
}
